<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input
        style="width: 200px;"
        class="filter-item"
        placeholder="手机号"
        v-model="queryForm.phone"
      ></el-input>
      <el-select
        clearable
        style="width: 170px"
        class="filter-item"
        v-model="queryForm.type"
        placeholder="请选择广告类型"
      >
        <el-option
          v-for="(val, key) in Dicts.AD_ORDER_TYPE"
          :key="key"
          :label="val"
          :value="key"
        ></el-option>
      </el-select>
      <el-button
        class="filter-item"
        @click="doQuery"
        type="primary"
        icon="el-icon-search"
        >查询</el-button
      >
    </div>
    <el-table v-loading="loading" :data="records" style="width: 100%">
      <el-table-column prop="rowId" label="ID" width="200" align="center">
      </el-table-column>
      <el-table-column
        prop="userName"
        label="用户姓名"
        width="250"
        align="center"
      >
      </el-table-column>
      <el-table-column prop="phone" label="手机号" width="250" align="center">
      </el-table-column>
      <el-table-column prop="type" label="广告类型" width="250" align="center">
        <template slot-scope="scope">
          {{ Dicts.AD_ORDER_TYPE[scope.row.type] }}
        </template>
      </el-table-column>
      <el-table-column prop="title" label="广告标题" width="500" align="center">
      </el-table-column>
      <el-table-column prop="photo" label="图片" width="250" align="center">
        <template slot-scope="scope">
          <div v-viewer>
            <img
              style="width:30px;height:30px;border-radius:5px;"
              v-if="scope.row.photo"
              :src="$oss(scope.row.photo)"
            />
          </div>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryForm.current"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="queryForm.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="queryForm.total"
      >
      </el-pagination>
    </div>

    <!-- 详情 -->
    <el-dialog
      :title="`详情`"
      :visible.sync="detailsDialogFormVisible"
      width="46%"
    >
      <el-form :model="checkForm" label-width="140px" ref="checkForm">
        <el-row>
          <el-col :span="20">
            <el-form-item label="广告标题:" prop="title">
              {{ checkForm.status }}
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="10">
            <el-form-item label="用户姓名:" prop="userName">
              {{ checkForm.userName }}
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="广告类型:" prop="type">
              {{ Dicts.AD_ORDER_TYPE[checkForm.type] }}
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="10">
            <el-form-item label="企业名称:" prop="companyName">
              {{ checkForm.companyName }}
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="10">
            <el-form-item label="图片:" prop="photo">
              <template slot-scope="scope">
                <img
                  :src="$oss(checkForm.photo)"
                  alt
                  style="width: 280px;height: 170px"
                />
              </template>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { queryUserAd } from '@/api/ad'
import 'viewerjs/dist/viewer.css'
import Viewer from 'v-viewer'
import Vue from 'vue'
Vue.use(Viewer)
export default {
  name: 'userAd',
  data() {
    return {
      checkDialogFormVisible: false,
      detailsDialogFormVisible: false,
      loading: false,
      queryForm: {
        current: 1,
        pages: 0,
        total: 0,
        size: 10,
        title: undefined
      },
      checkForm: {
        rowId: 0,
        userName: '',
        voucherCode: '',
        type: '',
        title: '',
        photo: '',
        orderTime: '',
        payTime: '',
        orderAmount: '',
        realpayAmount: '',
        lastPayTime: '',
        status: '',
        checkName: '',
        checkTime: '',
        checkResult: '',
        remark: '',
        payType: '',
        externalTransno: ''
      },
      records: []
    }
  },
  created() {
    // 初始化一次oss client,如果初始化过一次返回上一次初始化对象
    this.initOssClient().then(_ => {
      this.doQuery()
    })
  },
  methods: {
    handleCurrentChange(current) {
      this.queryForm.current = current
      this.doQuery()
    },
    handleSizeChange(size) {
      this.queryForm.size = size
      this.doQuery()
    },
    doQuery() {
      this.loading = true
      queryUserAd(this.queryForm).then(({ data: { data } }) => {
        this.queryForm.current = data.current
        this.queryForm.pages = data.pages
        this.queryForm.total = data.total
        this.queryForm.size = data.size
        this.records = data.records
        this.loading = false
      })
    },
    detailsOrder(row) {
      this.detailsDialogFormVisible = true
      this.checkForm = {
        rowId: row.rowId,
        userName: row.userName,
        voucherCode: row.voucherCode,
        type: row.type,
        title: row.title,
        photo: row.photo,
        orderTime: row.orderTime,
        payTime: row.payTime,
        orderAmount: row.orderAmount,
        realpayAmount: row.realpayAmount,
        lastPayTime: row.lastPayTime,
        status: row.status,
        payType: row.payType,
        externalTransno: row.externalTransno,
        checkResult: row.checkResult,
        remark: row.remark,
        checkTime: row.checkTime,
        checkName: row.checkName
      }
    }
  },
  components: {}
}
</script>

<style scoped></style>
